import arcgis
from arcgis.gis import GIS
from arcgis.raster import *
# from arcgis.layers import Service arcgis.__version__'2.1.0.2'
# Connect to your ArcGIS Enteprise or AGOL
portal_url = 'https://gis.earthdata.nasa.gov/portal'
gis = GIS(portal_url) #anonymous usermap_view = gis.map("Arizona") # Adjust the location as needed
# Add the raster layer directly to the map
# map_view.add_layer(md_raster) # Assuming md_raster is your Raster object
map_view#query Portal Content
query="TEMPO"
max_items=3
portal_content = gis.content.advanced_search(query=query, max_items=max_items)
for item in portal_content['results']:
display (item)item = portal_content['results'][0]
itemitem_gettempo=item.id
tempo'474a1016d4d54f97b99e6926328e01c1'
tempo_layer = gis.content.get(tempo)
tempo_layer# gis = GIS()
map_view = gis.map()
map_view.content.add('474a1016d4d54f97b99e6926328e01c1')
# map_view.add_layer('474a1016d4d54f97b99e6926328e01c1')
map_view.time_slider = True
map_viewAttributeError: 'MapView' object has no attribute 'content'
item_layers = item.layers
for layer in item_layers:
print(layer)layer= item_layers[0]
print(layer.url)
layermd_raster = Raster(layer.url, is_multidimensional=True, engine=None, gis=gis)
md_raster.variable_namesvar_name = md_raster.variable_names[0]
var_nametime_variable_values = md_raster.multidimensional_info['multidimensionalInfo']['variables'][0]['dimensions'][0]['values']len(time_variable_values)single_time_var = time_variable_values[333]
single_time_var# Apply the multidimensional filter to subset the raster for the specified time
filtered_raster = multidimensional_filter(
raster=md_raster,
variables=[var_name],
dimension={"StdTime": single_time_var}
)filtered_rastermap_viewmap_view.add_layer(filtered_raster)from arcgis.mapping import ImageryLayer
# Assuming `filtered_raster` is your subsetted Raster
imagery_layer = ImageryLayer(filtered_raster.url)
# Add the ImageryLayer to the MapView
# map_view = gis.map("Arizona")
map_view.add_layer(imagery_layer)
map_viewfrom arcgis.mapping import MapView# Display the filtered raster on a map
map_view = gis.map("Your Location") # Replace with a relevant location or leave blank
map_view.add_layer(filtered_raster)
map_view#Print Image Service Multidimensional Info
print(md_raster.multidimensional_info)item_content = gis.content.get(item.id)
item_contentm = gis.map()
m.add_layer(item_content)for layer in item.layers:
print(layer.properties.name)m = gis.map('Arizona', 3)
mm.add_layer(gpw_bdc_layer)pm25_layer = item.layers[0]
pm25_layerfor fn in gpw_bdc_layer.properties.rasterFunctionInfos:
print(fn['name'])gpw_bdc_layer.properties.rasterFunctionInfos[0]['name']from arcgis.raster.functions import apply
try:
processed_layer = apply(gpw_bdc_layer, "None") # Use a valid function name here
# Add the processed layer to the map
map_view = gis.map('Arizona')
map_view.add_layer(processed_layer)
map_view
except Exception as e:
print("An error occurred:", e)gis = GIS("home")
map_view = gis.map('Arizona')
map_view.add_layer(gpw_bdc_layer)
map_view#Assuming `gpw_bdc_layer` is your raster layer item
# Apply a raster function to the layer
processed_layer = apply(gpw_bdc_layer, gpw_bdc_layer.properties.rasterFunctionInfos[0]['name'])
# Create a MapView and add the processed layer directly
map_view = gis.map('Arizona')
map_view.add_layer(processed_layer)
map_viewshow(gpw_bdc_layer)item_content
item_content = gis.content.get(item_id) # Retrieve the item by ID
# Create a MapView and add the item as a layer
map_view = gis.map()
map_view.add_layer(item_content)
map_viewmap = gis.map()
map.add_layer(item)
map